<?php

$config = [
    'id' => 'base.app',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'timeZone' => 'PRC',
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        'request' => [
            'cookieValidationKey' => 'dmxl.base',
            'enableCsrfValidation' => false,
            'parsers' => [
                'application/json' => '\yii\web\JsonParser',
            ],
        ],
        'response' => [
            'format' => yii\web\Response::FORMAT_JSON,
            'charset' => 'UTF-8',
        ],
        'errorHandler' => [
            'class' => '\common\domain\components\ApiErrorHandler',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            // 'flushInterval' => 1,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['info', 'error', 'warning'],
                    'logFile' => ROOT_PATH . '/runtime/log/app.log',
                    // 追加ReqID
                    'prefix' => function ($message) {
                        $reqId = Yii::$app->params['reqId'];
                        $url = Yii::$app->getRequest()->getUrl();
                        return "[{$reqId}][{$url}]";
                    },
                    // 日志格式 可选 _GET, _POST, _FILES，_COOKIE，_SESSION, _SERVER
                    'logVars' => [],
                    // 排除 404
                    'except' => [
                        'yii\web\HttpException:404',
                    ],
                    // 最大文件大小 kb单位
                    'maxFileSize' => 1024 * 50,
                    // 最多保留文件数量
                    'maxLogFiles' => 10,
                ],
            ],
        ],
        'user' => [
            'identityClass' => 'app\models\Admin',
            'enableSession' => false,
            'loginUrl' => null,
        ],
    ],
];

return $config;
